package com.aqie.easy.design;

import java.util.ArrayList;

/**
 * 705 设计哈希集合
 * ArrayList 删除是根据下标删除
 */
public class MyHashSet {
    public ArrayList<Integer> list = new ArrayList<>();
    public MyHashSet() {

    }

    public void add(int key) {
        if (contains(key)) return;
        list.add(key);
    }

    public void remove(int key) {
        for (int i = 0; i < list.size(); i++){
            if (list.get(i) == key) {
                Integer remove = list.remove(i);
            }
        }
    }

    /** Returns true if this set contains the specified element */
    public boolean contains(int key) {
        return list.contains(key);
    }

    public static void main(String[] args) {
        MyHashSet hashSet = new MyHashSet();
        hashSet.add(1);
        hashSet.add(2);
        hashSet.contains(1); // 返回 true
        hashSet.contains(3); // 返回 false (未找到)
        hashSet.add(2);
        hashSet.contains(2); // 返回 true

        System.out.println(hashSet.list);
        hashSet.remove(2);
        hashSet.contains(2);


        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);



    }
}
